// https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html
const AWS = require('aws-sdk');
const regions = require("../../common/awsRegions");
AWS.config.update({region: regions.region_ap_southeast_1});

const ec2 = new AWS.EC2();

const d = {};

d.createKeyPair = (params) => new Promise((resolve, reject) => {
  ec2.createKeyPair(params, function(err, data) {
    if (err) {
      reject(err);
    } // an error occurred
    else {
      resolve(data);
    }// successful response
  });
});

d.describeKeyPairs = (params) => new Promise((resolve, reject) => {
  ec2.describeKeyPairs(params, function(err, data) {
    if (err) {
      reject(err);
    } // an error occurred
    else {
      resolve(data);
    }// successful response
  });
});

d.describeInstances = (params) => new Promise((resolve, reject) => {
  ec2.describeInstances(params, function(err, data) {
    if (err) {
      reject(err);
    } // an error occurred
    else {
      resolve(data);
    }// successful response
  });
});

module.exports = d;